package com.helu.lubike.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.helu.lubike.R;
import com.helu.lubike.databinding.ActivityModifyUsernameBinding;
import com.helu.lubike.utils.Constants;
import com.helu.lubike.utils.SharedPreferencesUtils;
import com.helu.lubike.utils.Utils;

/**
 * @author helu  17-2-13 下午4:36
 * @description 修改用户名
 */

public class ModifyUserNameActivity extends AppCompatActivity {

    public static final int RESULT_CODE = 301;
    private String phoneNumber;
    private ActivityModifyUsernameBinding mInflate;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mInflate = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_modify_username, null, false);
        setContentView(mInflate.getRoot());

        initView();
        initListener();
        initData();
    }

    private void initView() {
        phoneNumber = getIntent().getStringExtra(Constants.PHONE_NUMBER);
        mInflate.inputPhone.setHint(phoneNumber);
    }

    private void initListener() {
        mInflate.cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        mInflate.ensure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String newPhoneNumber = mInflate.inputPhone.getText().toString();
                if (!newPhoneNumber.startsWith("1")) {
                    Utils.showToast(ModifyUserNameActivity.this, "请输入正确的手机号码");
                    return;
                }

                //存进去
                SharedPreferencesUtils.save(ModifyUserNameActivity.this, Constants.PHONE_NUMBER, newPhoneNumber);

                Intent data = new Intent();
                data.putExtra(Constants.PHONE_NUMBER, newPhoneNumber);
                setResult(RESULT_CODE, data);
                finish();
            }
        });
    }


    private void initData() {

    }
}
